<template>
  <div id="app" class="wrapper wrapper-content animated fadeInRight v-cloak" v-cloak>
    <div class="row">
      <div class="ibox float-e-margins">
        <div class="ibox-content col-md-12">
          <form id="sewageTreatmentForm" method="post" class="form m-t" @submit.prevent="save()" accept-charset="UTF-8">
            <input type="hidden" name="id" v-model="item.id"/>
            <input type="hidden" name="token" v-model="item.token"/>
            <input type="hidden" name="newFlag" v-model="newFlag"/>
            <div class="clearfix "></div>
            <div class="col-md-12 b-r">

              <div class="form-group col-md-6 clearfix">
                <label class="col-md-8 control-label">登记编码：</label>
                <div class="col-md-12">
                  <input id="bean-code" name="code" v-model="item.code" class="form-control" type="text"
                      placeholder="请输入登记编码" required="" aria-required="true" aria-describedby="bean-code-error"
                      maxlength="55" aria-invalid="true">
                  <span id="bean-code-error" class="help-block m-b-none" for="bean-code"></span>
                </div>
              </div>

              <div class="form-group col-md-6 clearfix">
                <label class="col-md-8 control-label">设施名称：</label>
                <div class="col-md-12">
                  <input id="bean-name" name="name" v-model="item.name" class="form-control" type="text"
                      placeholder="请输入设施名称" required="" aria-required="true" aria-describedby="bean-name-error"
                      maxlength="55" aria-invalid="true">
                  <span id="bean-name-error" class="help-block m-b-none" for="bean-name"></span>
                </div>
              </div>

              <div class="form-group col-md-6 clearfix">
                <label class="col-md-8 control-label">所在河道：</label>
                <div class="col-md-12">
                  <select data-placeholder="选择所在河道" id="bean-riverId" name="riverId" class="form-control" required=""
                      aria-required="true" aria-describedby="bean-riverId-error" aria-invalid="true">
                    <option value="">--请选择所在河道--</option>
                    <option v-if="rivers != null && rivers.length > 0"
                        v-for="(river, index) in rivers" :value="river.id"
                        :selected="river.id == item.riverId">{{ river.name }}
                    </option>
                  </select>
                  <span id="bean-riverId-error" class="help-block m-b-none" for="bean-riverId"></span>
                </div>
              </div>

              <div class="form-group col-md-6 clearfix">
                <label class="col-md-8 control-label">投运时间：</label>
                <div class="col-md-12">
                  <input autocomplete="off" id="bean-startDate" name="startDate" v-model="item.startDate"
                      class="laydate-icon form-control layer-date" type="text" placeholder="请输入投运时间"
                      aria-describedby="bean-startDate-error" aria-invalid="true">
                  <span id="bean-startDate-error" class="help-block m-b-none" for="bean-startDate"></span>
                </div>
              </div>
              <div class="form-group col-md-6 clearfix">
                <label class="col-md-8 control-label">设计处理能力（亿m³/日）：</label>
                <div class="col-md-12">
                  <input id="bean-processCapacity" name="processCapacity" v-model="item.processCapacity"
                      class="form-control" type="text" placeholder="请输入设计处理能力（亿m³/日）"
                      aria-describedby="bean-processCapacity-error" aria-invalid="true">
                  <span id="bean-processCapacity-error" class="help-block m-b-none" for="bean-processCapacity"></span>
                </div>
              </div>

              <div class="form-group col-md-6 clearfix">
                <label class="col-md-8 control-label">处理工艺：</label>
                <div class="col-md-12">
                  <input id="bean-technology" name="technology" v-model="item.technology" class="form-control"
                      type="text" placeholder="请输入处理工艺" aria-describedby="bean-technology-error" maxlength="64"
                      aria-invalid="true">
                  <span id="bean-technology-error" class="help-block m-b-none" for="bean-technology"></span>
                </div>
              </div>

              <div class="form-group col-md-6 clearfix">
                <label class="col-md-8 control-label">所在位置：</label>
                <div class="col-md-12">
                  <input id="bean-address" name="address" v-model="item.address" class="form-control" type="text"
                      placeholder="请输入所在位置" aria-describedby="bean-address-error" maxlength="64" aria-invalid="true">
                  <span id="bean-address-error" class="help-block m-b-none" for="bean-address"></span>
                </div>
              </div>

              <div class="form-group col-md-6 clearfix">
                <label class="col-md-8 control-label">起点经度：
                  <a href="javascript:;" @click="getCoordinate()"
                      class="label label-success"><i class="fa fa-coordinate"></i>坐标拾取</a>
                </label>
                <div class="col-md-12">
                  <input id="bean-longitude" name="longitude" v-model="item.longitude" class="form-control" type="text"
                      placeholder="请输入起点经度" required="" aria-required="true" aria-describedby="bean-longitude-error"
                      maxlength="32" aria-invalid="true">
                  <span id="bean-longitude-error" class="help-block m-b-none" for="bean-longitude"></span>
                </div>
              </div>

              <div class="form-group col-md-6 clearfix">
                <label class="col-md-8 control-label">起点纬度：</label>
                <div class="col-md-12">
                  <input id="bean-latitude" name="latitude" v-model="item.latitude" class="form-control" type="text"
                      placeholder="请输入起点纬度" required="" aria-required="true" aria-describedby="bean-latitude-error"
                      maxlength="32" aria-invalid="true">
                  <span id="bean-latitude-error" class="help-block m-b-none" for="bean-latitude"></span>
                </div>
              </div>

              <div class="form-group col-md-6 clearfix">
                <label class="col-md-8 control-label">责任单位：</label>
                <div class="col-md-12">
                  <input id="bean-responsibleAgency" name="responsibleAgency" v-model="item.responsibleAgency"
                      class="form-control" type="text" placeholder="请输入责任单位"
                      aria-describedby="bean-responsibleAgency-error" maxlength="32" aria-invalid="true">
                  <span id="bean-responsibleAgency-error" class="help-block m-b-none"
                      for="bean-responsibleAgency"></span>
                </div>
              </div>

              <div class="form-group col-md-6 clearfix">
                <label class="col-md-8 control-label">责任人：</label>
                <div class="col-md-12">
                  <input id="bean-principal" name="principal" v-model="item.principal" class="form-control" type="text"
                      placeholder="请输入责任人" aria-describedby="bean-principal-error" maxlength="32"
                      aria-invalid="true">
                  <span id="bean-principal-error" class="help-block m-b-none" for="bean-principal"></span>
                </div>
              </div>

              <div class="form-group col-md-6 clearfix">
                <label class="col-md-8 control-label">联系电话：</label>
                <div class="col-md-12">
                  <input id="bean-phone" name="phone" v-model="item.phone" class="form-control" type="text"
                      placeholder="请输入联系电话" required="" aria-required="true" aria-describedby="bean-phone-error"
                      maxlength="32" aria-invalid="true">
                  <span id="bean-phone-error" class="help-block m-b-none" for="bean-phone"></span>
                </div>
              </div>

              <div class="form-group col-md-6 clearfix">
                <label class="col-md-8 control-label">归口管理单位：</label>
                <div class="col-md-12">
                  <input id="bean-manageCompany" name="manageCompany" v-model="item.manageCompany" class="form-control"
                      type="text" placeholder="请输入归口管理单位" aria-describedby="bean-manageCompany-error" maxlength="64"
                      aria-invalid="true">
                  <span id="bean-manageCompany-error" class="help-block m-b-none" for="bean-manageCompany"></span>
                </div>
              </div>

              <div class="form-group col-md-12 clearfix">
                <vue-area areaId="areaIds"
                    areaName="areaNames"
                    :areaIdVal="item.areaIds||staff.dto().areaId"
                    :areaNameVal="item.areaNames||staff.dto().areaName"
                    :areaFixed="item.areaIds||staff.dto().areaId"
                    :selectBy="item.areaIds||staff.dto().areaId"
                    areaRequired="true,true,true,false,false">
                </vue-area>
              </div>

              <div class="form-group col-md-6 clearfix">
                <label class="col-md-8 control-label">备注：</label>
                <div class="col-md-12">
                  <textarea id="bean-memo" name="memo" class="form-control" placeholder="请输入备注"
                      aria-describedby="bean-memo-error" maxlength="255"
                      aria-invalid="true">{{item.memo}}</textarea>
                  <span id="bean-memo-error" class="help-block m-b-none" for="bean-memo"></span>
                </div>
              </div>
            </div>

            <div class="clearfix "></div>
            <div class="col-12 text-center" style="height: 50px;">
              <div>
                <input class="btn btn-primary" type="submit" value="保存"/> | <a @click="lbox.closeMyBoxLayer()" class="btn btn-danger" href="javascript:">返回</a>
              </div>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
</template>
<script type="text/javascript">
import '@/assets/css/style.css'

import $ from '@/assets/js/jquery-vendor.js'
import 'jquery.cookie'
import axios from 'axios'
import '@/assets/js/validate/validation-vendor.js'

import 'layui-laydate/dist/theme/default/laydate.css'
import laydate from 'layui-laydate'
import {apiUtil, axiosContentType, site} from '@/assets/js/boss'
import vueArea from '@/components/vue-area'

export default {
  components: {
    'vue-area': vueArea
  },
  data() {
    return {
      item: {},
      rivers: [],
      newFlag: 0,
      uuidToken: ''
    }
  },
  mounted() {
    let that = window.$vueApp = this;
    document.getElementsByTagName('body')[0].className = 'fixed-sidebar full-height-layout';
    $('#sewageTreatmentForm').validate();
    that.staff.init(function () {
      that.newFlag = sessionStorage.getItem(site.sewageTreatment.info);
      if (that.newFlag) that.uuidToken = apiUtil.guid();
      if (apiUtil.existSessionKey(site.sewageTreatment.info)) {
        that.info();
      }
    });
    that.riverList();

    if (!that.item.areaIds || that.item.areaIds == null) {
      that.item.areaIds = '51,5110,511025,,'; // 默认选择省市县区域
    }
    laydate.render({elem: '#bean-startDate', event: 'click'});
  },
  methods: {
    info() {
      let that = this;
      axios.get(site.sewageTreatment.info + sessionStorage.getItem(site.sewageTreatment.info), {}).then(function (response) {
        const result = response.data;
        if (result.code === 0) {
          that.item = result.data;
        } else {
          alert(result.message);
        }
      });
    },
    riverList() {
      let that = this;
      axios.get(site.riverInfo.list, {}).then(function (response) {
        var result = response.data;
        if (result.code === 0) {
          that.rivers = result.data;
        } else {
          alert(result.message);
        }
      });
    },
    save() {
      let that = this;
      if ($('#sewageTreatmentForm').valid()) {
        axios.post(site.sewageTreatment.save, $('#sewageTreatmentForm').serialize(),
            axiosContentType.xWwwFormUrlencoded).then(function (response) {
          const result = response.data;
          // console.info("获取数据.." + JSON.stringify(result));
          if (result.code === 0) {
            parent.$vueApp.page();
            alert('保存成功!');
            that.lbox.closeMyBoxLayer()
          } else {
            alert(result.message);
          }
        });
      }
    },
    getCoordinate() { // 坐标拾取页面
      this.lbox.openMyBoxLayer('经纬度坐标拾取', site.map.mapll);
    },
    setMapSite(longitude, latitude, address) { // 坐标拾取回调
      $('#bean-longitude').val(longitude);
      $('#bean-latitude').val(latitude);
      this.item.longitude = longitude;
      this.item.latitude = latitude;
    }
  }
}
</script>

